﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Interactivity;
using System.Windows;
using AccessControl.Contracts.Models;
using AccessControl.Wpf.Printing;

namespace AccessControl.Wpf.Actions
{
	class PrintEventsAction : TriggerAction<Button>
	{
		#region Fields

		private static readonly Type s_ThisType = typeof(PrintEventsAction);

		#endregion

		#region Dependency Properties

		public static readonly DependencyProperty EventsProperty = DependencyProperty.Register(
			"Events",
			typeof(IList<IEvent>),
			s_ThisType,
			new PropertyMetadata(null));

		public IList<IEvent> Events
		{
			get { return (IList<IEvent>)GetValue(EventsProperty); }
			set { SetValue(EventsProperty, value); }
		}
		
		#endregion

		#region Overrides

		protected override void Invoke(object parameter)
		{
			bool? result;

			/* Create the print dialog */
			PrintDialog printDialog = new PrintDialog();
			result = printDialog.ShowDialog();
			if (result.HasValue && result.Value)
			{
				var paginator = new EventsPaginator()
				{
					Events = Events,
					PageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight)
				};

				printDialog.PrintDocument(paginator, "Events list");
			
			}
		}

		#endregion
	}
}
